package com.android.kotlincoroutinemvvmdemo.view
import android.content.Context
import android.graphics.Canvas
import android.graphics.CornerPathEffect
import android.graphics.Paint
import android.graphics.Path
import android.util.AttributeSet
import com.android.kotlincoroutinemvvmdemo.R

/*
* CopyView
* */
class CopyView @JvmOverloads constructor(
    context: Context,
    attributeSet: AttributeSet? = null
) : BaseView(context, attributeSet) {

    private val mPaint by lazy {
        Paint().apply {
            isAntiAlias = true
            isDither = true
            strokeCap = Paint.Cap.ROUND
            style = Paint.Style.STROKE
            color = context.resources.getColor(R.color.color_F405B9)
            pathEffect = CornerPathEffect(context.resources.getDimension(R.dimen.dp_3))
            strokeWidth = context.resources.getDimension(R.dimen.dp_1)
        }
    }

    private val mPath by lazy {
        Path()
    }

    override fun onDraw(canvas: Canvas?) {
        super.onDraw(canvas)
        setBackgroundColor(context.resources.getColor(R.color.color_F3F3F3))
        canvas?.apply {
            val cx = mWidth.toFloat() / 2
            val cy = mHeight.toFloat() / 2
            save()
            translate(cx + cx / 14, cy)
            mPath.apply {
                reset()
                moveTo(-cx / 7, -cy * 6 / 7)
                lineTo(cx * 5 / 7, -cy * 6 / 7)
                lineTo(cx * 5 / 7, cy * 4 / 7)
                lineTo(-cx / 7, cy * 4 / 7)
                close()
            }
            drawPath(mPath, mPaint)

            mPath.apply {
                reset()
                moveTo(0F, cy * 4 / 7)
                lineTo(0F, cy * 6 / 7)
                lineTo(-cx * 6 / 7, cy * 6 / 7)
                lineTo(-cx * 6 / 7, -cy * 4 / 7)
                lineTo(-cx * 1 / 7, -cy * 4 / 7)
            }
            drawPath(mPath, mPaint)
        }
    }
}